import React, { Component } from 'react'

export default function withForm(WrapperComponent) {
  return class extends Component {
    static displayName = 'with' + WrapperComponent.name
    state = {
      username: '',
      password: '',
      repassword: '',
    }
    handle = (name) => (e) => {
      this.setState({
        [name]: e.target.value.trim(),
      })
    }
    render() {
      return (
        <WrapperComponent
          {...this.state}
          {...this.props} // 定义高阶组件,一定要写传递props的代码
          handle={this.handle}
        ></WrapperComponent>
      )
    }
  }
}
